/*
 * EditAction.java
 *
 * Created on 28 marzec 2007, 15:05
 *
 */

package arocms.news;

import arocms.business.News;
import arocms.business.NewsDAO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author arek
 */
public class EditAction extends Action{
    
    private Logger log = Logger.getLogger(this.getClass());

    private static final String SUCCESS = "success";
    private static final String FAILURE = "failure";
    
    /** Creates a new instance of EditAction */
    public EditAction() {
    }

    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
        String id = request.getParameter("id");
        /*NewsFormBean newsBean = (NewsFormBean) form;
        News news = new News();
        news.setCreation_date(new Date());
        news.setDescription(newsBean.getDescription());
        news.setTitle(newsBean.getTitle());
        Long pk = new Long(id);
        news.setId(pk);
        new NewsDAO().*/

        NewsFormBean newsForm = new NewsFormBean();
        News news = new NewsDAO().find(new Long(id));
        newsForm.setId(news.getId().toString());
        newsForm.setTitle(news.getTitle());
        newsForm.setHeading(news.getHeading());
        newsForm.setDescription(news.getDescription());
        request.setAttribute(mapping.getAttribute(),newsForm);
        return mapping.findForward(SUCCESS);
    }

}
